<template>
    <div class="chat_notice_frame">
        <el-card v-for="v in notices" :key="v.roomId">
            xxx邀请你进入 {{v.roomName }} <el-button type="primary" @click='accept(v.roomId)'>同意</el-button> <el-button type="danger" @click="reject(v.roomId)">拒绝</el-button>
        </el-card>
    </div>
 
</template>

<script>
import { mapState } from 'vuex'; 
export default {
name:'YChatNotice',
data(){
    return {
        notices:[]
    }
},
computed:{
...mapState('userAbout',['user','token'])
},
mounted(){
    this.__load()
this.$pubsub.subscribe('reloadNotice',this.__load)
},
methods:{
    __load(){
        this.$basicAxios(this.$ms.get_invite_noticec(this.token),(resp)=>{this.notices = resp.data.data})
    }, 
    accept(roomId){
        this.$websocket.accept_room(roomId,this.token).then((resp)=>{
            if(resp.data.code!=200) this.notify('error',resp.data.msg)
            else this.notify('success',"你已进入该房间")
        },resp=>this.notify('error',`[ ${resp.name} ] ${resp.message}`))
    },
    reject(roomId){
        this.$websocket.reject_room(roomId,this.token).then((resp)=>{
            if(resp.data.code!=200) this.notify('error',resp.data.msg)
            else this.notify('success',"你已拒绝邀请")
        },resp=>this.notify('error',`[ ${resp.name} ] ${resp.message}`))
    }
}
}
</script>

<style>
.chat_notice_frame{
    width:100%;
    height:100%
}
</style>